package com.compass.doctor.dialog

import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.fragment.app.FragmentActivity
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.callback.RxCancellationCallBack
import com.compass.doctor.databinding.DialogRefusalBinding
import com.compass.doctor.ui.prescription.viewmodel.PrescribeViewModel
import com.compass.framework.base.BaseDialog
import com.compass.framework.base.BaseDialogFragment
import com.compass.framework.ext.onClick
import com.compass.framework.toast.TipsToast

/**
 * Description： 作废Dialog
 * Date:2024/3/1 10:59
 */
class CancellationDialog {

    class Builder(
        activity: FragmentActivity,
        id: String,
        onRxCancellationCallBack: RxCancellationCallBack
    ) : BaseDialogFragment.Builder<Builder>(activity) {

        private var orderId: String
        private var onRxCancellationCallBack: RxCancellationCallBack? = null
        private val mBinding: DialogRefusalBinding =
            DialogRefusalBinding.inflate(LayoutInflater.from(activity))

        init {
            orderId = id
            this.onRxCancellationCallBack = onRxCancellationCallBack
            initView()
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
            gravity = Gravity.BOTTOM
            mBinding.refusalInfo.text = "作废理由"
            mBinding.edtSuggest.hint = "请输入处方作废理由"
            mBinding.tvRefusal.onClick {
                var suggest = mBinding.edtSuggest.text.toString().trim()
                if (suggest.isNotEmpty()) {
                    onRxCancellationCallBack?.onCancellationCallBack(orderId,suggest)
                } else {
                    TipsToast.showTips("请输入处方作废理由")
                }
            }

            mBinding.tvCancel.onClick {
                dismiss()
            }

        }


        fun dismissDialog() {
            dismiss()
        }
    }
}